from pymongo import MongoClient

class DBMongo:
    def __init__(self, host, port):
        if host != "" and port != 0:
            self.db = MongoClient(host, port)
        else:
            self.db = MongoClient()

    def auth(self, user, passw, db):
        self.db[db].authenticate(user, passw)

    def query(self, db, coll, cond):
        hd = self.db[db][coll]
        cursor = hd.find()
        data = []
        for item in cursor:
            data.append(item)
        return data

    def insert(self, db, coll, data):
        self.db[db][coll].insert_one(data)

